% Modified from the example in
% http://www.texample.net/tikz/examples/d-flip-flops-and-shift-register/


%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxx Mimo Shape with two antennas xxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\makeatletter

\newif\ifleftantennas

% The keys that the user can provide are all the keys below, except
% "leftantennas" (use the "right antennas" or "left antennas" keys instead)
\pgfkeys{
  /mimonode/leftantennas/.is if=leftantennas,
  /pgf/.cd,
  right antennas/.code={\pgfkeys{/mimonode/leftantennas=false}},
  left antennas/.code={\pgfkeys{/mimonode/leftantennas=true}},
  % minimum width/.initial=1.5cm,
  % minimum height/.initial=2cm,
  circle fill color/.initial=white,
  circle stroke color/.initial=black,
  circle radius/.initial=2mm,
  antenna offset/.initial=0.3 cm,
  antenna base height/.initial=0.2 cm,
  antenna side/.initial=0.4cm,
}



% Macro with the common code to draw an antenna. Before calling this macro
% (inside the backgroundpath or similar)you need to set the values of
% \pgf@x and \pgf@y to point to the start of the antenna. 
\def\drawantenna{
  % Store the current positions in \pgf@xa and \pgf@ya
  \pgf@xa=\pgf@x 
  \pgf@ya=\pgf@y
  \pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}

  \advance\pgf@xa by \antennaoffset
  \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathclose
  \pgfmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}

  % \pgf@xb and \pgf@yb will have the coordinate with the starting point to
  % draw the triangle
  \pgf@xb=\pgf@xa \pgf@yb=\pgf@ya
  \advance\pgf@yb by \antennabaseheight cm
  \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
  
  % See section "Internals of How Point Commands Work" of the pgf manual to
  % understand pgf@process
  \pgf@process{
    \pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\pgfpointpolar{60}{\pgfkeysvalueof{/pgf/antenna side}}}
  }
  \pgf@xc=\pgf@x 
  \pgf@yc=\pgf@y
  \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
  
  
  \pgf@process{
    \pgfpointadd{\pgfpoint{\pgf@xc}{\pgf@yc}}{\pgfpointpolar{180}{\pgfkeysvalueof{/pgf/antenna side}}}
  }
  \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
  
  \pgf@process{
    \pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\pgfpointpolar{240}{\pgfkeysvalueof{/pgf/antenna side}}}
  }
  \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}


% Macro with the common code to draw the ellipses. Before calling this
% macro (inside the backgroundpath or similar)you need to set the values of
% \pgf@x and \pgf@y to point to the center of the ellipses.
\def\drawellipses{
  % Store the current positions in \pgf@xa and \pgf@ya
  \pgf@xa=\pgf@x 
  \pgf@ya=\pgf@y
  
  % See section "Internals of How Point Commands Work" of the pgf manual to
  % understand pgf@process
  \pgf@process{\pgfpathcircle{\pgfpoint{\pgf@xa}{-1pt}}{1pt}}
  \pgf@process{\pgfpathcircle{\pgfpoint{\pgf@xa}{2pt}}{1pt}}
  \pgf@process{\pgfpathcircle{\pgfpoint{\pgf@xa}{5pt}}{1pt}}
}


% The code to determine the x coordinate for the anchors in the start of
% each antenna is common for all antennas. Therefore, it is better to
% define a macro with it and just call the macro when define the respective
% savedanchor.
\def\antennaStartXCoordinate{
  % x position
  \ifleftantennas
  % Anchor position when the "left antennas" key is used
  \pgf@x=-.5\wd\pgfnodeparttextbox
  % Advance by the inner xsep
  \pgfmathsetlength\pgf@xc{-\pgfkeysvalueof{/pgf/inner xsep}}
  \advance\pgf@x by \pgf@xc%
  %
  % If the resulting x coordinate is lower the value required for the
  % minimum width then the value for the minimum width will be used instead
  \setlength{\pgf@xa}{-\pgfshapeminwidth}
  \ifdim\pgf@x>.5\pgf@xa
  \pgf@x=.5\pgf@xa
  \fi
  \else
  % Anchor position when the "left antennas" key is not used or when
  % the "right antennas" key is used.
  \pgf@x=.5\wd\pgfnodeparttextbox % width of the box
  \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}
  \advance\pgf@x by \pgf@xc%
  \setlength{\pgf@xa}{\pgfshapeminwidth}
  \ifdim\pgf@x<.5\pgf@xa
  \pgf@x=.5\pgf@xa
  \fi
  \fi
}
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxx mimotwo shape declaration xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

% xxxxxxxxxx First we define some savedmacros xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\pgfdeclareshape{mimotwo}{
  \savedmacro\antennaoffset{
    \ifleftantennas
      \def\antennaoffset{-\pgfkeysvalueof{/pgf/antenna offset}}
    \else
      \def\antennaoffset{\pgfkeysvalueof{/pgf/antenna offset}}
    \fi
  }

  \savedmacro\antennabaseheight{
    \def\antennabaseheight{\pgfkeysvalueof{/pgf/antenna base height}}
  }

  \savedmacro\shapewidth{
    \def\shapewidth{\pgfkeysvalueof{/pgf/minimum width}}
  }

  \savedmacro\shapeheight{
    \def\shapeheight{\pgfkeysvalueof{/pgf/minimum height}}
  }
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  % xxxxxxxxxx Now we define the savedanchors xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  \savedanchor\northeast{%
    \pgf@y=.5\ht\pgfnodeparttextbox % height of the box, ignoring the depth
    \pgf@x=.5\wd\pgfnodeparttextbox % width of the box
    %
    % -----> Take the inner sep into account
    \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}
    \advance\pgf@x by \pgf@xc%
    \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}
    \advance\pgf@y by \pgf@yc%
    % -----
    % Test if the minimum width and height are respected. If not, set it as
    % the minimum width/height.
    \setlength{\pgf@xa}{\shapewidth}
    \ifdim\pgf@x<.5\pgf@xa
    \pgf@x=.5\pgf@xa
    \fi
    \setlength{\pgf@ya}{\shapeheight}
    \ifdim\pgf@y<.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    %
    % -----> Take the outer sep into account
    % Now that we have the values of x and y we could stop here. However,
    % in order to take into account the "outer sep" we need to add it to
    % the anchor position(the idea is that the anchor will be outside the
    % actual node (by the outer sep ammount). The default value of the
    % outer sep is half the length of a line. Note that we are including
    % the outer sep value in the anchor definition, but it should not be
    % taken into account when drawing the background. Therefore, we need to
    % remove this when drawing the rectangle box.
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \advance\pgf@x by\pgf@xa%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@y by\pgf@ya%
  }

  \savedanchor\southwest{%
    \pgf@y=-.5\ht\pgfnodeparttextbox % height of the box, ignoring the depth
    \pgf@x=-.5\wd\pgfnodeparttextbox % width of the box
    %
    % -----> Take the inner sep into account
    \pgfmathsetlength\pgf@xc{-\pgfkeysvalueof{/pgf/inner xsep}}
    \advance\pgf@x by \pgf@xc%
    \pgfmathsetlength\pgf@yc{-\pgfkeysvalueof{/pgf/inner ysep}}
    \advance\pgf@y by \pgf@yc%
    % 
    % Test if the minimum width and height are respected. If not, set it as
    % the minimum width/height.
    \setlength{\pgf@xa}{-\shapewidth}
    \ifdim\pgf@x>.5\pgf@xa
    \pgf@x=.5\pgf@xa
    \fi
    \setlength{\pgf@ya}{-\shapeheight}
    \ifdim\pgf@y>.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    %
    % -----> Take the outer sep into account (see comment in the northeast savedanchor)
    \pgfmathsetlength\pgf@xa{-\pgfkeysvalueof{/pgf/outer xsep}}%
    \advance\pgf@x by\pgf@xa%
    \pgfmathsetlength\pgf@ya{-\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@y by\pgf@ya%
  }

  % This anchor position will depend if the "left antennas" option was
  % passed or not.
  \savedanchor{\anchorA}{
    % -----> y position for the first antenna
    \pgf@y=.5\ht\pgfnodeparttextbox
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y<.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    \pgf@y=0.4\pgf@y
    %
    % -----> x position
    \antennaStartXCoordinate
  }

  % This anchor position will depend if the "left antennas" option was
  % passed or not
  \savedanchor{\anchorB}{
    % -----> y position for the first antenna
    \pgf@y=-.5\ht\pgfnodeparttextbox
    \setlength{\pgf@ya}{-\pgfshapeminheight}
    \ifdim\pgf@y>.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    \pgf@y=0.6\pgf@y
    %
    % -----> x position
    \antennaStartXCoordinate
  }
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  % xxxxxxxxxx Inherit anchor border from rectangle xxxxxxxxxxxxxxxxxxxxxxx
  \inheritanchorborder[from=rectangle]
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  
  
  % xxxxxxxxxx Now we define the regular anchors xxxxxxxxxxxxxxxxxxxxxxxxxx
  \anchor{A}{
    \pgf@process{\anchorA}
  }
  \anchor{B}{
    \pgf@process{\anchorB}
  }

  % We can inherit the "usual" from rectangle. They depend on the
  % "\southwest" and "\northeast" savedanchors but this will use our
  % version instead of the rectangle's version.
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}

  \anchor{text}
  {
    \pgf@process{\pgfpointorigin}
    \advance\pgf@x by -.5\wd\pgfnodeparttextbox%
    \advance\pgf@y by -.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by +.5\dp\pgfnodeparttextbox%
  }
  
  % -----> Define some more useful anchors
  \anchor{first antenna base start}{
    \pgf@process{\anchorA}
  }
  
  \anchor{second antenna base start}{
    \pgf@process{\anchorB}
  }

  \anchor{first antenna base end}{
    \pgf@process{\anchorA}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.2cm%
  }
  \anchor{second antenna base end}{
    \pgf@process{\anchorB}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.2cm%
  }

  \anchor{first antenna}{
    %\csname pgf@anchor@mimotwo@first antenna base start\endcsname
    \pgf@process{\anchorA}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.4cm%
  }
  \anchor{second antenna}{
    %\csname pgf@anchor@mimotwo@second antenna base start\endcsname
    \pgf@process{\anchorB}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.4cm%
  }
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


  % xxxxxxxxxx Draw the background xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  \backgroundpath{
    % Rectangle box
    % \pgfpathrectanglecorners{\southwest}{\northeast}
    \pgfpathrectanglecorners
    { % First corner of the rectangle
      \pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}
    }
    { % Second corner of the rectangle
      \pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    }

    %%%%%%% Draw the first antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \pgf@process{\anchorA}
    % The drawantenna command only needs that the pgf@x and pgf@y variables
    % are correctly set. This is done by calling the anchor A
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


    %%%%% Draw the second antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \anchorB
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  }
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxx End of mimotwo shape declaration xxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxx Mimo Shape with three antennas xxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\pgfdeclareshape{mimothree}{

  % xxxxxxxxxx Define savedanchors xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  % First we Inherit savedanchors (and savedmacro's) from mimotwo
  \inheritsavedanchors[from=mimotwo]  

  % We redefine savedanchors "anchorA" and "anchorB" and define "anchorC"
  \savedanchor{\anchorA}{
    \pgf@y=.5\ht\pgfnodeparttextbox
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y<.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    \pgf@y=0.5\pgf@y
    %
    % x position
    \antennaStartXCoordinate
  }

  \savedanchor{\anchorC}{
    % y position for the first antenna
    \pgf@y=-.5\ht\pgfnodeparttextbox
    \setlength{\pgf@ya}{-\pgfshapeminheight}
    \ifdim\pgf@y>.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    \pgf@y=0.9\pgf@y
    %
    % x position
    \antennaStartXCoordinate
  }

  % B is in the middle of A and C
  \savedanchor{\anchorB}{
    % y position
    % First we get y position of anchor A
    \pgf@y=.5\ht\pgfnodeparttextbox
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y<.5\pgf@ya
    \pgf@y=.5\pgf@ya
    \fi
    \pgf@ya=0.5\pgf@y
    % Then we get y position of anchor C
    \pgf@y=-.5\ht\pgfnodeparttextbox
    \setlength{\pgf@yc}{-\pgfshapeminheight}
    \ifdim\pgf@y>.5\pgf@yc
    \pgf@y=.5\pgf@yc
    \fi
    \pgf@yc=0.9\pgf@y
    % y position of anchor B is in the middle of anchor A and C
    \pgf@y=0.5\pgf@yc
    \advance\pgf@y by 0.5\pgf@ya
    %
    % x position
    \antennaStartXCoordinate
  }
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


  % xxxxxxxxxx Inherit anchor border from mimotwo xxxxxxxxxxxxxxxxxxxxxxxxx
  \inheritanchorborder[from=mimotwo]
  % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


  % xxxxxxxxxx Inherit normal anchors from mimotwo xxxxxxxxxxxxxxxxxxxxxxxx
  \inheritanchor[from=mimotwo]{center}
  \inheritanchor[from=mimotwo]{north}
  \inheritanchor[from=mimotwo]{east}
  \inheritanchor[from=mimotwo]{south}
  \inheritanchor[from=mimotwo]{west}
  \inheritanchor[from=mimotwo]{north east}
  \inheritanchor[from=mimotwo]{north west}
  \inheritanchor[from=mimotwo]{south west}
  \inheritanchor[from=mimotwo]{south east}
  \inheritanchor[from=mimotwo]{text}
  \inheritanchor[from=mimotwo]{A}
  \inheritanchor[from=mimotwo]{B}
  \inheritanchor[from=mimotwo]{first antenna base start}
  \inheritanchor[from=mimotwo]{second antenna base start}
  \inheritanchor[from=mimotwo]{first antenna base end}
  \inheritanchor[from=mimotwo]{second antenna base end}
  \inheritanchor[from=mimotwo]{first antenna}
  \inheritanchor[from=mimotwo]{second antenna}

  % -----> Define the normal anchors
  \anchor{C}{\anchorC}
  \anchor{third antenna base start}{
    \pgf@process{\anchorC}
  }
  \anchor{third antenna base end}{
    \pgf@process{\anchorC}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.2cm%
  }
  \anchor{third antenna}{
    %\csname pgf@anchor@mimothree@third antenna base start\endcsname
    \pgf@process{\anchorC}
    \advance\pgf@x by \antennaoffset%
    \advance\pgf@y by 0.4cm%
  }

  % -----> Draw the rectangle box and the antennas
  \backgroundpath{
    % Rectangle box
    \pgfpathrectanglecorners
    {\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    %%%%%%% Draw the first antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Você pode usar \pgf@anchor@SHAPE_NAME@ANCHOR_NAME para mudar o \pgf@x
    % e o \pgf@y para as coordenadas de uma âncora. Só que se você resolver
    % mudar o nome do shape depois vai ter que mudar todas as linhas que
    % contem o SHAPE_NAME. Melhor usar o csname como na linha abaixo.
    \csname pgf@anchor@\shape@name @A\endcsname
    %\pgf@anchor@mimothree@A
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


    %%%%% Draw the second antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% \pgf@anchor@mimothree@B
    \csname pgf@anchor@\shape@name @B\endcsname
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    

    %%%%% Draw the third antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% \pgf@anchor@mimothree@C
    \csname pgf@anchor@\shape@name @C\endcsname
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  }
}
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxx End of mimothree shape declaration xxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx





%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxx Mimo Shape with "many" antennas xxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\pgfdeclareshape{mimoind}{
  % -----> Inherit saved anchor from mimothree
  \inheritsavedanchors[from=mimothree]

  % -----> Inherit anchor border from mimothree
  \inheritanchorborder[from=mimothree]

  % -----> Inherit normal anchors from mimothree
  \inheritanchor[from=mimothree]{center}
  \inheritanchor[from=mimothree]{north}
  \inheritanchor[from=mimothree]{east}
  \inheritanchor[from=mimothree]{south}
  \inheritanchor[from=mimothree]{west}
  \inheritanchor[from=mimothree]{north east}
  \inheritanchor[from=mimothree]{north west}
  \inheritanchor[from=mimothree]{south west}
  \inheritanchor[from=mimothree]{south east}
  \inheritanchor[from=mimothree]{text}
  \inheritanchor[from=mimothree]{A}
  \inheritanchor[from=mimothree]{B}
  \inheritanchor[from=mimothree]{C}
  \inheritanchor[from=mimothree]{first antenna base start}
  \inheritanchor[from=mimothree]{second antenna base start}
  \inheritanchor[from=mimothree]{third antenna base start}
  \inheritanchor[from=mimothree]{first antenna base end}
  \inheritanchor[from=mimothree]{second antenna base end}
  \inheritanchor[from=mimothree]{third antenna base end}
  \inheritanchor[from=mimothree]{first antenna}
  \inheritanchor[from=mimothree]{second antenna}
  \inheritanchor[from=mimothree]{third antenna}

  % -----> Draw the rectangle box and the antennas
  \backgroundpath{
    % Rectangle box
    \pgfpathrectanglecorners
    {\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    %%%%%%% Draw the first antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Você pode usar \pgf@anchor@SHAPE_NAME@ANCHOR_NAME para mudar o \pgf@x
    % e o \pgf@y para as coordenadas de uma âncora. Só que se você resolver
    % mudar o nome do shape depois vai ter que mudar todas as linhas que
    % contem o SHAPE_NAME. Melhor usar o csname como na linha abaixo.
    \csname pgf@anchor@\shape@name @A\endcsname
    %\pgf@anchor@mimoind@A
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


    %%%%% Draw the second antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% \pgf@anchor@mimoind@B
    \csname pgf@anchor@\shape@name @second antenna base end\endcsname
    %\drawantenna
    \drawellipses
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    

    %%%%% Draw the third antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% \pgf@anchor@mimoind@C
    \csname pgf@anchor@\shape@name @C\endcsname
    \drawantenna
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  }
}
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxx End of mimoind shape declaration xxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxx Boxtwo Node xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\pgfdeclareshape{boxtwo}{

  \inheritsavedanchors[from=mimotwo]

  % -----> Inherit from rectangle
  \inheritanchorborder[from=mimotwo]

  % -----> Define same anchor a normal rectangle has
  \inheritanchor[from=mimotwo]{center}
  \inheritanchor[from=mimotwo]{north}
  \inheritanchor[from=mimotwo]{east}
  \inheritanchor[from=mimotwo]{south}
  \inheritanchor[from=mimotwo]{west}
  \inheritanchor[from=mimotwo]{north east}
  \inheritanchor[from=mimotwo]{north west}
  \inheritanchor[from=mimotwo]{south west}
  \inheritanchor[from=mimotwo]{south east}
  \inheritanchor[from=mimotwo]{text}

  % -----> Define anchors for signal ports

  % See section "Internals of How Point Commands Work" of the pgf manual to
  % understand pgf@process
  \anchor{A}{
    \pgf@process{\northeast}%
    \pgf@x=0pt
    \pgf@y=0.5\pgf@y%
  }

  \anchor{B}{
    \pgf@process{\northeast}%
    \pgf@x=0pt
    \pgf@y=-0.5\pgf@y%
  }

  % -----> Draw the rectangle box and the three circles
  \backgroundpath{
    % Rectangle box
    {
      \pgfpathrectanglecorners
    {\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
      \pgfusepath{stroke,fill}
    }
    
    % The two circles
    {
      \csname pgf@anchor@\shape@name @A\endcsname
      \pgfcircle{\pgfpoint{\pgf@x}\pgf@y{}}{\pgfkeysvalueof{/pgf/circle radius}}
      \csname pgf@anchor@\shape@name @B\endcsname
      \pgfcircle{\pgfpoint{\pgf@x}\pgf@y{}}{\pgfkeysvalueof{/pgf/circle radius}}
      \pgfsetfillcolor{\pgfkeysvalueof{/pgf/circle fill color}}
      \pgfsetstrokecolor{\pgfkeysvalueof{/pgf/circle stroke color}}
      \pgfusepath{stroke,fill}
    }
  }
}
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxx End of boxtwo shape declaration xxxxxxxxxxxxxxxxxxxxxxxxx
% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxx Boxthree Node xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
%% xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\pgfdeclareshape{boxthree}{

  \inheritsavedanchors[from=boxtwo]

  % -----> Inherit from rectangle
  \inheritanchorborder[from=boxtwo]

  % -----> Define same anchor a normal rectangle has
  \inheritanchor[from=boxtwo]{center}
  \inheritanchor[from=boxtwo]{north}
  \inheritanchor[from=boxtwo]{east}
  \inheritanchor[from=boxtwo]{south}
  \inheritanchor[from=boxtwo]{west}
  \inheritanchor[from=boxtwo]{north east}
  \inheritanchor[from=boxtwo]{north west}
  \inheritanchor[from=boxtwo]{south west}
  \inheritanchor[from=boxtwo]{south east}
  \inheritanchor[from=boxtwo]{text}

  % -----> Define anchors for signal ports

  % See section "Internals of How Point Commands Work" of the pgf manual to
  % understand pgf@process
  \anchor{A}{
    \northeast
    \pgf@x=0pt
    \pgf@y=0.6\pgf@y%
  }

  \anchor{B}{
    \pgf@x=0pt
    \pgf@y=0pt
  }

  \anchor{C}{
    \northeast
    \pgf@x=0pt
    \pgf@y=-0.6\pgf@y%
  }


  % -----> Draw the rectangle box and the three circles
  \backgroundpath{
    % Rectangle box
    {
      \pgfpathrectanglecorners
    {\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
      \pgfusepath{stroke,fill}
    }
    
    % The three circles
    {
      \csname pgf@anchor@\shape@name @A\endcsname
      \pgfcircle{\pgfpoint{\pgf@x}\pgf@y{}}{\pgfkeysvalueof{/pgf/circle radius}}
      \csname pgf@anchor@\shape@name @B\endcsname
      \pgfcircle{\pgfpoint{\pgf@x}\pgf@y{}}{\pgfkeysvalueof{/pgf/circle radius}}
      \csname pgf@anchor@\shape@name @C\endcsname
      \pgfcircle{\pgfpoint{\pgf@x}\pgf@y{}}{\pgfkeysvalueof{/pgf/circle radius}}
      \pgfsetfillcolor{\pgfkeysvalueof{/pgf/circle fill color}}
      \pgfsetstrokecolor{\pgfkeysvalueof{/pgf/circle stroke color}}
      \pgfusepath{stroke,fill}
      }
  }
}

\makeatother

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "testmimoshapes.tex"
%%% TeX-PDF-mode: t
%%% End: 
